//
//  MainViewController.m
//  O2Cat
//
//  Created by xiabin on 15/12/16.
//  Copyright © 2015年 QiDao.Purifier. All rights reserved.
//

#import "MainViewController.h"
#import "CHCircleGaugeView.h"
#import "SettingPageController.h"
#import "CustomActionSheet.h"
#import "LocationService.h"
#import "WXApi.h"
#import "CityInfoModel.h"
#import "UMNetworkManager.h"
#import "HardwareService.h"
#import "AddDeviceS1EnterController.h"

@interface MainViewController () <CustomActionSheetDelegate, UMAsyncJobDelegate> {
    int getLocationInfoJobId;
    int getCityInfoJobId;
    int pm25Local;
}

@property (nonatomic,strong) CHCircleGaugeView* PMGaugeView;

@property (nonatomic,strong) UILabel* modeStyleLabel;
@property (nonatomic,strong) UIImageView* modeStyleIcon;
@property (nonatomic,strong) UILabel* tempLabel;
@property (nonatomic,strong) UILabel* wetLabel;
@property (nonatomic,strong) UILabel* pmLabel;
@property (nonatomic,strong) UILabel* tempValLabel;
@property (nonatomic,strong) UILabel* wetValLabel;
@property (nonatomic,strong) UILabel* pmValLabel;

//@property (nonatomic,strong) UIView* powerSwitchContainer;
//@property (nonatomic,strong) UIView* modeSwitchContainer;
//@property (nonatomic,strong) UIView* speedSwitchContainer;
@property (nonatomic,strong) UIImageView* SwitchContainer;
@property (nonatomic,strong) UIImageView* Infobg;

@property (nonatomic,strong) UISegmentedControl* modeCtrl;
@property (nonatomic,strong) UISlider* powerCtrl;
@property (nonatomic,strong) UISegmentedControl* speedCtrl;
@property (nonatomic,strong) UILabel* modeLabel;
@property (nonatomic,strong) UILabel* powerLabel;
@property (nonatomic,strong) UILabel* speedLabel;

@property (nonatomic,strong) UIView* sepline1;
@property (nonatomic,strong) UIView* sepline2;

@end

@implementation MainViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    [self.view addSubview:self.Infobg];
    [self.view addSubview:self.PMGaugeView];

    [self.view addSubview:self.modeStyleIcon];
    [self.view addSubview:self.modeStyleLabel];
    [self.view addSubview:self.tempLabel];
    [self.view addSubview:self.tempValLabel];
    [self.view addSubview:self.wetValLabel];
    [self.view addSubview:self.wetLabel];
    [self.view addSubview:self.pmLabel];
    [self.view addSubview:self.pmValLabel];
    //[self.view addSubview:self.powerSwitchContainer];
    //[self.view addSubview:self.modeSwitchContainer];
    //[self.view addSubview:self.speedSwitchContainer];
    [self.view addSubview:self.SwitchContainer];
    [self.view addSubview:self.sepline1];
    [self.view addSubview:self.sepline2];
    [self.view bringSubviewToFront:self.sepline1];
    [self.view bringSubviewToFront:self.sepline2];
    [self.SwitchContainer addSubview:self.modeCtrl];
    [self.SwitchContainer addSubview:self.powerCtrl];
    [self.SwitchContainer addSubview:self.speedCtrl];
    [self.SwitchContainer addSubview:self.modeLabel];
    [self.SwitchContainer addSubview:self.powerLabel];
    [self.SwitchContainer addSubview:self.speedLabel];
    
    self.view.backgroundColor = QGMainPageBG;
    
    [self layoutSubViews];
    // Do any additional setup after loading the view.
}

- (void) viewWillAppear:(BOOL)animated {
    [self setupNavStyle];
    [self updateInfo];
    [self updateView];
}

- (void) viewDidAppear:(BOOL)animated {
    if (QGHardwareService.deviceID == nil || QGHardwareService.deviceID.length <= 0) {
        AddDeviceS1EnterController* pageAdd = [AddDeviceS1EnterController new];
        [self.navigationController pushViewController:pageAdd animated:NO];
        [QGHardwareService setDeviceID:@"default"];
    }
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

-(void) updateInfo {
    getLocationInfoJobId = [QGLocationService getCurrentLocation:self];
}
//{35,75,115,150,250};
-(void) updateView {
    pm25Local = 51;
    if(pm25Local < 35) {
        self.PMGaugeView.gaugeTintColor = PM25L0Color;
    } else if (pm25Local<75) {
        self.PMGaugeView.gaugeTintColor = PM25L1Color;
    } else if (pm25Local<115) {
        self.PMGaugeView.gaugeTintColor = PM25L2Color;
    } else if (pm25Local<150) {
        self.PMGaugeView.gaugeTintColor = PM25L3Color;
    } else {
        self.PMGaugeView.gaugeTintColor = PM25L4Color;
    }
}

- (void) setupNavStyle {
    //self.navigationController.navigationBar.translucent = YES;
    [self.navigationController.navigationBar setBackgroundColor:[UIColor clearColor]];
    UIImage* image = [UIImage imageNamed:@"emptyNavBg"];
    [self.navigationController.navigationBar setBackgroundImage:image forBarMetrics:UIBarMetricsDefault];  //
    [self.navigationController.navigationBar setShadowImage:image];

    self.navigationItem.title = @"奇道空气进化器";
    
    UIButton* settingBtn = [Utils NavButtonStyleNormalBLeft:YES NormalImg:@"setting" AndHightLight:@"setting"];
    [settingBtn addTarget:self action:@selector(showSettingPage) forControlEvents:UIControlEventTouchUpInside];
    self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView:settingBtn];
    
    UIButton* shareBtn = [Utils NavButtonStyleNormalBLeft:NO NormalImg:@"share" AndHightLight:@"share"];
    [shareBtn addTarget:self action:@selector(doSocialShare) forControlEvents:UIControlEventTouchUpInside];
    self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView:shareBtn];
}

-(void) showSettingPage {
    SettingPageController* settingPage = [SettingPageController new];
    [self.navigationController pushViewController:settingPage animated:NO];
}

-(void) doSocialShare {
    /*UIGraphicsBeginImageContext(self.view.frame.size);
    [self.navigationController.view.layer renderInContext:UIGraphicsGetCurrentContext()];
    UIImage*  viewImage=UIGraphicsGetImageFromCurrentImageContext();
    UIGraphicsEndImageContext();
    UIImageWriteToSavedPhotosAlbum(viewImage,nil,nil,nil);*/
    
    NSMutableArray* btnArray = [[NSMutableArray alloc] init];
    //if ([WXApi isWXAppInstalled]) {
        [btnArray addObject:[CustomActionSheetButton buttonWithImage:[UIImage imageNamed:@"shareWechat"] title:@"微信"]];
        [btnArray addObject:[CustomActionSheetButton buttonWithImage:[UIImage imageNamed:@"shareFriends"] title:@"朋友圈"]];
    //}
    CustomActionSheet* sheet = [[CustomActionSheet alloc] initWithButtons:btnArray];
    sheet.delegate = self;
    [sheet showInView:self.view];
}

-(void)choseAtIndex:(int)index {
    /*NSString *aString = [NSString stringWithFormat:@"%d", _post.postId];
    NSData *someData = [aString dataUsingEncoding:NSUTF8StringEncoding];
    
    NSData* DesEcry = [Utils DESEncrypt:someData WithKey:DESKey];
    NSString* base64codeuid = [Utils base64EncodedStringFrom:DesEcry];
    
    NSString* url= SHARE_POST(base64codeuid);
    
    NSString* imgUrl = @"https://mmbiz.qlogo.cn/mmbiz/eSwicWJGjdQ0tg3HXBIF9r4WfzMuD8rxSEiaMSehbnxuMBNOl7u1TCZAIOVvwYicEXH8JBNkWcv7xO803S5PJO2zA/0?wx_fmt=png";
    if (_post.postImageArray.count > 0) {
        imgUrl = _post.postImageArray[0];
    }
    
    if(index == QQIndex)
    {
        [MobClick event:@"kBarPageShareToQQ"];
        [SocialShare shareToQQwithTitle:_post.postTitle Content:_post.postContent URL:url Image:imgUrl];
    }
    else if(index == QZoneIndex)
    {
        [MobClick event:@"kBarPageShareToQZone"];
        [SocialShare shareToQZonewithTitle:_post.postTitle Content:_post.postContent URL:url Image:imgUrl];
    }
    else if(index == WechatIndex)
    {
        [MobClick event:@"kBarPageShareToWechat"];
        [SocialShare shareToWeChatwithTitle:_post.postTitle Content:_post.postContent URL:url Image:imgUrl];
    }
    else if(index == FriendIndex)
    {
        [MobClick event:@"kBarPageShareToFriends"];
        [SocialShare shareToWeChatFriendsTitle:_post.postTitle Content:_post.postContent URL:url Image:imgUrl];
    }*/
}

-(void)onPower:(id)sender {
    NSString* imageName;
    NSLog(@"%f", self.powerCtrl.value);
    if (self.powerCtrl.value == 0 || self.powerCtrl.value == 1) {
        if (self.powerCtrl.value == 0) {
            imageName = @"slideopen";
        } else if (self.powerCtrl.value == 1){
            imageName = @"slideclose";
        }
        UIImage* sliderImg = [UIImage imageNamed:imageName];
        UIImage* scrae = [Utils OriginImage:sliderImg scaleToSize:CGSizeMake(3*SCREEN_SIZE_WIDTH/8,50*[Utils phoneHeightfix])];
    
        [_powerCtrl setThumbImage: scrae forState:UIControlStateNormal];

    }
}

- (void)modeControlSelected:(id)sender
{
    switch (self.modeCtrl.selectedSegmentIndex) {
        case 0:
            break;
        case 1:
            break;
        case 2:
            break;
        default:
            break;
    }
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

-(void)UMAsyncJobDone:(UMJobStatus)emJobStatus JobCookie:(int)JobID And:(id)JobRet {
    if (JobID == getLocationInfoJobId) {
        NSLog(@"%@", JobRet);
        getCityInfoJobId = [QGNetworkManager GetCityInfo:JobRet Callback:self];
    } else if(JobID == getCityInfoJobId) {
        CityInfoModel* cityinfo = [CityInfoModel modelwithDic:JobRet];
        
        self.tempValLabel.text = [Utils getTemptureDes:cityinfo.temp];
        self.wetValLabel.text = [Utils getWetDes:cityinfo.wet];
        self.pmValLabel.text = [Utils getPMDes:cityinfo.pm25];
    }
}

-(void) layoutSubViews {
    //顶部排布
    __weak __typeof(&*self)weakSelf = self;
    
    [self.modeStyleIcon mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.mas_equalTo(weakSelf.view.mas_right).offset(-20);
        make.top.mas_equalTo(weakSelf.view.mas_top).offset(NavH);
        make.height.mas_equalTo(20);
        make.width.mas_equalTo(20);
    }];
    
    [self.modeStyleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.mas_equalTo(weakSelf.modeStyleIcon.mas_centerY);
        make.right.mas_equalTo(weakSelf.modeStyleIcon.mas_left).offset(-10);
        //make.height.mas_equalTo(2*SCREEN_SIZE_WIDTH/3);
        //make.width.mas_equalTo(2*SCREEN_SIZE_WIDTH/3);
    }];
    
    [self.PMGaugeView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(weakSelf.modeStyleIcon.mas_bottom).offset(20*[Utils phoneHeightfix]);
        make.centerX.mas_equalTo(weakSelf.view.mas_centerX).offset(0);
        make.height.mas_equalTo(220*[Utils phoneWidthfix]);
        make.width.mas_equalTo(220*[Utils phoneWidthfix]);
    }];
    
    [self.tempLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(weakSelf.PMGaugeView.mas_bottom).offset(0);
        make.centerX.mas_equalTo(weakSelf.view.mas_left).offset(1*SCREEN_SIZE_WIDTH/6);
    }];
    
    [self.tempValLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(weakSelf.tempLabel.mas_bottom).offset(5);
        make.centerX.mas_equalTo(weakSelf.tempLabel.mas_centerX);
    }];
    
    [self.wetLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(weakSelf.tempLabel.mas_top);
        make.centerX.mas_equalTo(weakSelf.view.mas_left).offset(3*SCREEN_SIZE_WIDTH/6);
    }];
    
    [self.wetValLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(weakSelf.tempLabel.mas_bottom).offset(5);
        make.centerX.mas_equalTo(weakSelf.wetLabel.mas_centerX);
    }];
    
    [self.pmLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(weakSelf.tempLabel.mas_top);
        make.centerX.mas_equalTo(weakSelf.view.mas_left).offset(5*SCREEN_SIZE_WIDTH/6);
    }];
    
    [self.pmValLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(weakSelf.pmLabel.mas_bottom).offset(5);
        make.centerX.mas_equalTo(weakSelf.pmLabel.mas_centerX);
    }];
    
    [self.sepline1 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(weakSelf.tempLabel.mas_top).offset(-5);
        make.left.mas_equalTo(weakSelf.view.mas_left).offset(SCREEN_SIZE_WIDTH/3);
        make.width.mas_equalTo(1);
        make.height.mas_equalTo(50);
    }];
    
    [self.sepline2 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(weakSelf.sepline1.mas_top);
        make.left.mas_equalTo(weakSelf.view.mas_left).offset(2*SCREEN_SIZE_WIDTH/3);
        make.width.mas_equalTo(1);
        make.height.mas_equalTo(50);
    }];
    
    [self.SwitchContainer mas_makeConstraints:^(MASConstraintMaker *make) {
        make.bottom.mas_equalTo(weakSelf.view.mas_bottom).offset(0);
        make.centerX.mas_equalTo(weakSelf.view.mas_centerX).offset(0);
        make.height.mas_equalTo(240*[Utils phoneHeightfix]);
        make.width.mas_equalTo(SCREEN_SIZE_WIDTH);
    }];
    
    [self.Infobg mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(weakSelf.view.mas_top).offset(0);
        make.bottom.mas_equalTo(weakSelf.SwitchContainer.mas_top);
        make.centerX.mas_equalTo(weakSelf.view.mas_centerX).offset(0);
        //make.height.mas_equalTo(240*[Utils phoneHeightfix]);
        make.width.mas_equalTo(SCREEN_SIZE_WIDTH);
    }];

    /*
     [self.speedSwitchContainer mas_makeConstraints:^(MASConstraintMaker *make) {
     make.bottom.mas_equalTo(weakSelf.view.mas_bottom).offset(0);
     make.centerX.mas_equalTo(weakSelf.view.mas_centerX).offset(0);
     make.height.mas_equalTo(80*[Utils phoneHeightfix]);
     make.width.mas_equalTo(SCREEN_SIZE_WIDTH);
     }];
     
     [self.modeSwitchContainer mas_makeConstraints:^(MASConstraintMaker *make) {
        make.bottom.mas_equalTo(weakSelf.speedSwitchContainer.mas_top).offset(1);
        make.centerX.mas_equalTo(weakSelf.view.mas_centerX).offset(0);
        make.height.mas_equalTo(80*[Utils phoneHeightfix]);
        make.width.mas_equalTo(SCREEN_SIZE_WIDTH);
    }];
    
    [self.powerSwitchContainer mas_makeConstraints:^(MASConstraintMaker *make) {
        make.bottom.mas_equalTo(weakSelf.modeSwitchContainer.mas_top).offset(1);
        make.centerX.mas_equalTo(weakSelf.view.mas_centerX).offset(0);
        make.height.mas_equalTo(80*[Utils phoneHeightfix]);
        make.width.mas_equalTo(SCREEN_SIZE_WIDTH);
    }];*/
    
    [self.powerCtrl mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(weakSelf.SwitchContainer.mas_top).offset(20);
        make.right.mas_equalTo(weakSelf.SwitchContainer.mas_right).offset(-20);
        make.height.mas_equalTo(40*[Utils phoneHeightfix]);
        make.width.mas_equalTo(3*SCREEN_SIZE_WIDTH/4);
    }];
    
    [self.modeCtrl mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.mas_equalTo(weakSelf.SwitchContainer.mas_centerY);
        make.right.mas_equalTo(weakSelf.SwitchContainer.mas_right).offset(-20);
        make.height.mas_equalTo(40*[Utils phoneHeightfix]);
        make.width.mas_equalTo(3*SCREEN_SIZE_WIDTH/4);
    }];
    
    [self.speedCtrl mas_makeConstraints:^(MASConstraintMaker *make) {
        make.bottom.mas_equalTo(weakSelf.SwitchContainer.mas_bottom).offset(-20);
        make.right.mas_equalTo(weakSelf.SwitchContainer.mas_right).offset(-20);
        make.height.mas_equalTo(40*[Utils phoneHeightfix]);
        make.width.mas_equalTo(3*SCREEN_SIZE_WIDTH/4);
    }];
    
    [self.modeLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.mas_equalTo(weakSelf.modeCtrl.mas_centerY);
        make.left.mas_equalTo(weakSelf.SwitchContainer.mas_left).offset(20);
        //make.height.mas_equalTo(50);
        //make.width.mas_equalTo(1*SCREEN_SIZE_WIDTH/4);
    }];
    
    [self.powerLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.mas_equalTo(weakSelf.powerCtrl.mas_centerY);
        make.left.mas_equalTo(weakSelf.SwitchContainer.mas_left).offset(20);
        //make.height.mas_equalTo(50);
        //make.width.mas_equalTo(1*SCREEN_SIZE_WIDTH/4);
    }];
    
    [self.speedLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.mas_equalTo(weakSelf.speedCtrl.mas_centerY);
        make.left.mas_equalTo(weakSelf.SwitchContainer.mas_left).offset(20);
        //make.height.mas_equalTo(50);
        //make.width.mas_equalTo(1*SCREEN_SIZE_WIDTH/4);
    }];
}

-(CHCircleGaugeView*) PMGaugeView {
    if(_PMGaugeView == nil) {
        _PMGaugeView = [[CHCircleGaugeView alloc] init];
        [_PMGaugeView setTranslatesAutoresizingMaskIntoConstraints:NO];
        _PMGaugeView.trackTintColor = QGGauseGaugeColor;
        _PMGaugeView.trackWidth = 10;
        _PMGaugeView.gaugeWidth = 10;
        _PMGaugeView.gaugeTintColor = QGGauseGaugeColor;
        _PMGaugeView.textColor = QGTextWhite;
        _PMGaugeView.font = [UIFont systemFontOfSize: 60];
        _PMGaugeView.value = 0.42;
        _PMGaugeView.gaugeDegrees = 1.5*M_PI;
        _PMGaugeView.unitsString = @"室内PM2.5";
        _PMGaugeView.infoWords = @[@"优",@"良",@"轻度",@"中度",@"重度",@"严重"];
        _PMGaugeView.unitsStringTail = @"打败85%用户";
    }
    return _PMGaugeView;
}


-(UISegmentedControl*) modeCtrl {
    if(_modeCtrl == nil) {
        _modeCtrl = [[UISegmentedControl alloc] initWithItems:@[@"强", @"中", @"弱"]];
        [_modeCtrl addTarget:self action:@selector(modeControlSelected:) forControlEvents:UIControlEventValueChanged];
        [_modeCtrl setTitleTextAttributes:
         @{NSForegroundColorAttributeName : QGTextGrayL2,
           NSFontAttributeName: [UIFont systemFontOfSize:[Utils phoneFontL4]]} forState:UIControlStateNormal];
        [_modeCtrl setTitleTextAttributes:
         @{NSForegroundColorAttributeName : QGTextWhite,
           NSFontAttributeName: [UIFont systemFontOfSize:[Utils phoneFontL4]]} forState:UIControlStateSelected];
        _modeCtrl.backgroundColor = QGTextWhite;
        _modeCtrl.tintColor = QGNavBG;
        _modeCtrl.layer.cornerRadius = 20*[Utils phoneHeightfix];
        _modeCtrl.layer.borderWidth = 2;
        _modeCtrl.layer.borderColor = QGPageBG.CGColor;
        _modeCtrl.clipsToBounds = YES;
        [_modeCtrl setSelectedSegmentIndex:0];
    }
    return _modeCtrl;
}

-(UISegmentedControl*) speedCtrl {
    if(_speedCtrl == nil) {
        _speedCtrl = [[UISegmentedControl alloc] initWithItems:@[@"睡眠", @"正常", @"超强"]];
        [_speedCtrl addTarget:self action:@selector(modeControlSelected:) forControlEvents:UIControlEventValueChanged];
        [_speedCtrl setTitleTextAttributes:
         @{NSForegroundColorAttributeName : QGTextGrayL2,
           NSFontAttributeName: [UIFont systemFontOfSize:[Utils phoneFontL4]]} forState:UIControlStateNormal];
        [_speedCtrl setTitleTextAttributes:
         @{NSForegroundColorAttributeName : QGTextWhite,
           NSFontAttributeName: [UIFont systemFontOfSize:[Utils phoneFontL4]]} forState:UIControlStateSelected];
        _speedCtrl.backgroundColor = QGTextWhite;
        _speedCtrl.tintColor = QGNavBG;
        _speedCtrl.layer.cornerRadius = 20*[Utils phoneHeightfix];
        _speedCtrl.layer.borderWidth = 2;
        _speedCtrl.layer.borderColor = QGPageBG.CGColor;
        _speedCtrl.clipsToBounds = YES;
        [_speedCtrl setSelectedSegmentIndex:0];
    }
    return _speedCtrl;
}

- (UIImage *) clearPixel {
    CGRect rect = CGRectMake(0.0, 0.0, 1.0, 1.0);
    UIGraphicsBeginImageContext(rect.size);
    CGContextRef context = UIGraphicsGetCurrentContext();
    CGContextSetFillColorWithColor(context, [[UIColor clearColor] CGColor]);
    CGContextFillRect(context, rect);
    UIImage *image = UIGraphicsGetImageFromCurrentImageContext();
    UIGraphicsEndImageContext();
    return image;
}


-(UISlider*) powerCtrl {
    if (_powerCtrl == nil) {
        _powerCtrl = [[UISlider alloc] init];
        UIImage* sliderImg = [UIImage imageNamed:@"slideopen"];
        UIImage* scrae = [Utils OriginImage:sliderImg scaleToSize:CGSizeMake(3*SCREEN_SIZE_WIDTH/8,50*[Utils phoneHeightfix])];
        
        [_powerCtrl setThumbImage: scrae forState:UIControlStateNormal];
        _powerCtrl.backgroundColor = [UIColor clearColor];
        [_powerCtrl setMinimumTrackImage:[self clearPixel] forState:UIControlStateNormal];
        [_powerCtrl setMaximumTrackImage:[self clearPixel] forState:UIControlStateNormal];
        _powerCtrl.layer.borderWidth = 1;
        _powerCtrl.layer.borderColor = QGTextGrayL2.CGColor;
        _powerCtrl.layer.cornerRadius = 20*[Utils phoneHeightfix];
        [_powerCtrl addTarget:self action:@selector(onPower:) forControlEvents:UIControlEventValueChanged];
    }
    return _powerCtrl;
}

-(UILabel*) modeStyleLabel {
    if(_modeStyleLabel == nil) {
        _modeStyleLabel = [[UILabel alloc] init];
        _modeStyleLabel.text = @"自动模式";
        _modeStyleLabel.textColor = QGTextWhite;
        [_modeStyleLabel sizeToFit];
        _modeStyleLabel.font = [UIFont systemFontOfSize:[Utils phoneFontL3]];
    }
    return _modeStyleLabel;
}

-(UIImageView*) modeStyleIcon {
    if(_modeStyleIcon == nil) {
        _modeStyleIcon = [[UIImageView alloc] init];
        _modeStyleIcon.image = [UIImage imageNamed:@"auto"];
    }
    return  _modeStyleIcon;
}

-(UILabel*) tempLabel {
    if(_tempLabel == nil) {
        _tempLabel = [[UILabel alloc] init];
        _tempLabel.text = @"温度";
        _tempLabel.textColor = QGTextWhite;
        [_tempLabel sizeToFit];
        _tempLabel.font = [UIFont systemFontOfSize:[Utils phoneFontL3]];
    }
    return _tempLabel;
}

-(UILabel*) tempValLabel {
    if(_tempValLabel == nil) {
        _tempValLabel = [[UILabel alloc] init];
        _tempValLabel.text = @"22°C（偏凉）";
        _tempValLabel.textColor = QGTextWhite;
        [_tempValLabel sizeToFit];
        _tempValLabel.font = [UIFont systemFontOfSize:[Utils phoneFontL3]];
    }
    return _tempValLabel;
}

-(UILabel*) wetLabel {
    if(_wetLabel== nil) {
        _wetLabel = [[UILabel alloc] init];
        _wetLabel.text = @"湿度";
        _wetLabel.textColor = QGTextWhite;
        [_wetLabel sizeToFit];
        _wetLabel.font = [UIFont systemFontOfSize:[Utils phoneFontL3]];
    }
    return _wetLabel;
}

-(UILabel*) wetValLabel {
    if(_wetValLabel == nil) {
        _wetValLabel = [[UILabel alloc] init];
        _wetValLabel.text = @"52%（舒适）";
        _wetValLabel.textColor = QGTextWhite;
        [_wetValLabel sizeToFit];
        _wetValLabel.font = [UIFont systemFontOfSize:[Utils phoneFontL3]];
    }
    return _wetValLabel;
}

-(UILabel*) pmLabel {
    if(_pmLabel == nil) {
        _pmLabel = [[UILabel alloc] init];
        _pmLabel.text = @"室外PM2.5";
        _pmLabel.textColor = QGTextWhite;
        [_pmLabel sizeToFit];
        _pmLabel.font = [UIFont systemFontOfSize:[Utils phoneFontL3]];
    }
    return _pmLabel;
}

-(UILabel*) pmValLabel {
    if(_pmValLabel == nil) {
        _pmValLabel = [[UILabel alloc] init];
        _pmValLabel.text = @"189（中度污染）";
        _pmValLabel.textColor = QGTextWhite;
        [_pmValLabel sizeToFit];
        _pmValLabel.font = [UIFont systemFontOfSize:[Utils phoneFontL3]];
    }
    return _pmValLabel;
}

-(UIImageView*) Infobg {
    if(_Infobg == nil) {
        _Infobg = [[UIImageView alloc] init];
        _Infobg.image = [UIImage imageNamed:@"mainbg"];
    }
    return _Infobg;
}

-(UIImageView*) SwitchContainer {
    if(_SwitchContainer == nil) {
        _SwitchContainer = [[UIImageView alloc] init];
        _SwitchContainer.image = [UIImage imageNamed:@"mainctrlbt"];
        _SwitchContainer.userInteractionEnabled = YES;
        //_SwitchContainer.layer.borderColor = QGPageBG.CGColor;
        //_SwitchContainer.layer.borderWidth = 1;
    }
    return _SwitchContainer;
}

-(UILabel*) powerLabel {
    if(_powerLabel == nil) {
        _powerLabel = [[UILabel alloc] init];
        _powerLabel.text = @"电源";
        _powerLabel.textColor = QGTextBlack;
        [_powerLabel sizeToFit];
        _powerLabel.textAlignment = NSTextAlignmentCenter;
        _powerLabel.font = [UIFont systemFontOfSize:[Utils phoneFontL5]];
    }
    return _powerLabel;
}

-(UILabel*) modeLabel {
    if(_modeLabel == nil) {
        _modeLabel = [[UILabel alloc] init];
        _modeLabel.text = @"模式";
        _modeLabel.textColor = QGTextBlack;
        [_modeLabel sizeToFit];
        _modeLabel.textAlignment = NSTextAlignmentCenter;
        _modeLabel.font = [UIFont systemFontOfSize:[Utils phoneFontL5]];
    }
    return _modeLabel;
}

-(UILabel*) speedLabel {
    if(_speedLabel == nil) {
        _speedLabel = [[UILabel alloc] init];
        _speedLabel.text = @"风量";
        _speedLabel.textColor = QGTextBlack;
        [_speedLabel sizeToFit];
        _speedLabel.textAlignment = NSTextAlignmentCenter;
        _speedLabel.font = [UIFont systemFontOfSize:[Utils phoneFontL5]];
    }
    return _speedLabel;
}

-(UIView*) sepline1 {
    if(_sepline1 == nil) {
        _sepline1 = [[UIView alloc] init];
        _sepline1.backgroundColor = QGTextWhite;
    }
    return _sepline1;
}

-(UIView*) sepline2 {
    if(_sepline2 == nil) {
        _sepline2 = [[UIView alloc] init];
        _sepline2.backgroundColor = QGTextWhite;
    }
    return _sepline2;
}


@end
